package com.hh.demo.mapper;

import com.hh.demo.entity.Rent;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 吉吉国王
 * @since 2022-12-05
 */
@Mapper
public interface RentMapper extends BaseMapper<Rent> {
    //查询用户id 以及该用户的数量
    @Select("select user_id,count(*) as toyCount from rent" +
            " where state='已借出' group by user_id")
    List<Rent> queryCount();

    //查询全部的信息
    @Select("select * from rent")
    List<Rent> queryRent();

    //修改玩具状态
    @Update("update rent set state= '已归还', return_date =#{format} " +
            "where toy_id= #{toyId} and user_id= #{userId}")
    void returnToy(String toyId, String userId, String format);
}
